/**
 * Created by duwei on 2019/3/5.
 */
var ZiPai_HuWindow = Window.extend({
    _ccsFileName: res.ZiPai_HuWindow_json,
    _blockLayerOpacity: 0,
    initWindow: function (data, showNo, room) {
        var self = this;
        self.room = room;
        self.showNo = showNo;
        self.AcCards = data;
        self.denghu = self._nodeList['root.denghu'];
        self.hu = self._nodeList['root.hu'];
        self.bg = self._nodeList['root'];
        for (var i = 0; i < self.AcCards.length; i++) {
            (function (k) {
                var cardDate = self.AcCards[k];
                var cardId = cardDate['Cards'];
                var flag = cardDate['Type'];
                var denghu = ((flag & DENGHU) > 0) ? true : false;
                var huPai = new Card();
                huPai.setData(cardId);
                huPai.setPosition(cc.p(self.hu.getPositionX() + 180, denghu?self.denghu.getPositionY():self.hu.getPositionY()));
                self['hu_' + k] = huPai;
                self.bg.addChild(huPai);
                TouchUtil.setOnclickListener(huPai, function () {
                    self._clickPai(k);
                });
            })(i)
        }
    },
    /**
     * 点击时间
     * @private
     */
    _initClickListeners: function () {
        this._super();
        this._clickListeners = {
            'root.guo': '_clickGuo',
            'root.back': '_clickBack'
        };
    },
    /**
     * 点击过
     * @private
     */
    _clickGuo: function () {
        var self = this;
        self.room.userAct(GUO, self.showNo);
        self.removeFromParent(true);
    },
    _clickBack:function () {
        var self = this;
        self.room.nAction.setVisible(true);
        self.removeFromParent(true);
    },
    /**
     * 点击牌
     * @private
     */
    _clickPai: function (k) {
        var self = this;
        var date = self.AcCards[k];
        var flag = date['Type'];
        var denghu = ((flag & DENGHU) > 0) ? true : false;
        if(denghu){
            self.room.userAct(HUDENGHU, date['Cards']);
        }else{
            self.room.userAct(HU, date['Cards']);
        }
        self.removeFromParent(true);
    },
});